<template>
  <j-modal
    title="已添加的数据"
    :width="1200"
    :visible="visible"
    @cancel="visible = false"
    okText="确定添加"
    @ok="handleOk"
    switchFullscreen
  >
    <!--    搜索栏-->
    <div class="search-area">
      <!--      <div style="display: flex">-->
      <!--        <a-space @keyup.enter="handleSearch">-->
      <!--          物料名称：-->
      <!--          <a-input v-model="queryParam.materialName" style="width: 240px" placeholder="请输入物料名称"></a-input>-->
      <!--          物料类型：-->
      <!--          <j-dict-select-tag dict-code="hf_material_type,material_type_name,id" v-model="queryParam.materialType"-->
      <!--                             style="width: 160px" placeholder="请选择物料类型"></j-dict-select-tag>-->
      <!--        </a-space>-->
      <!--      </div>-->
      <div>
        <!--    操作栏-->
        <a-space>
          <!--          <a-button v-if="!editable" type="primary" icon="edit" @click="edit">编辑</a-button>-->
          <a-button type="primary" icon="plus" @click="fillFields">填充规格型号到客户品番</a-button>
          <a-button type="primary" icon="delete" @click="deleteData">删除</a-button>
        </a-space>
      </div>
    </div>
    <!--    内容栏-->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="tableData"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
      </a-table>
    </div>
  </j-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { postAction } from '@api/manage'

export default {
  name: 'HfBatchAddSalePriceList',
  mixins: [JeecgListMixin],
  props: {
    tableData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      visible: false,
      inputNumberWidth: '80px',
      editable: false,
      queryParams: {
        materialName: ''
      },
      disableMixinCreated: true,
      columns: [
        {
          title: '序号',
          fixed: 'left',
          width: 40,
          align: 'center',
          customRender: (t, r, index) => {
            return index + 1
          }
        },
        {
          title: '物料代码',
          dataIndex: 'materialCode',
          align: 'center',
          width: 120,
          fixed: 'left'
        },
        {
          title: '物料名称',
          dataIndex: 'materialName',
          align: 'center',
          width: 120,
          fixed: 'left'
        },
        {
          title: '规格型号',
          dataIndex: 'sap',
          align: 'center'
        },
        {
          title: '单价',
          dataIndex: 'price',
          align: 'center'
        },
        {
          title: '税率',
          dataIndex: 'tax',
          align: 'center'
        },
        {
          title: '含税单价',
          dataIndex: 'taxPrice',
          align: 'center'
        },
        {
          title: '执行时间',
          dataIndex: 'useTime',
          align: 'center'
        },
        {
          title: '客户',
          dataIndex: 'customId_dictText',
          align: 'center'
        },
        {
          title: '客户品番',
          dataIndex: 'saleCode',
          align: 'center'
        },
        {
          title: '简号',
          dataIndex: 'saleCode1',
          align: 'center'
        },
        {
          title: 'QAD',
          dataIndex: 'qad',
          align: 'center'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          align: 'center'
        }
      ],
      url: {
        list: '/sale/hfSalePrice/list',
        addOrEditBatch: '/sale/hfSalePrice/addOrEditBatch'
      }
    }
  },
  computed: {},
  methods: {
    loadData() {},
    deleteData() {
      this.$emit('delete', this.selectedRowKeys)
    },
    fillFields() {
      this.$emit('fillFields')
    },
    add(rows) {
      this.dataSource.push(...rows)
    },
    handleOk() {
      postAction(this.url.addOrEditBatch, this.tableData).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.$emit('ok', res.result)
        } else {
          this.$message.warning(res.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.search-area {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
</style>
